package cn.chenfeifx.core.controls.skins;

import cn.chenfeifx.core.common.ResourcesLoader;
import cn.chenfeifx.core.controls.CFEmpty;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.SkinBase;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;

public class CFEmptySkin extends SkinBase<CFEmpty> {

    private final ImageView imageView = new ImageView(ResourcesLoader.loadFxImage("/cn/chenfeifx/core/img/empty.png"));
    private final VBox vBox = new VBox(imageView);

    public CFEmptySkin(CFEmpty control) {
        super(control);
        imageView.fitWidthProperty().bind(control.sizeProperty());
        imageView.fitHeightProperty().bind(control.sizeProperty());
        imageView.setOpacity(0.7);
        vBox.setAlignment(Pos.CENTER);
        getChildren().setAll(vBox);
        //
        vBox.getChildren().add(control.getBottomNode());
        control.bottomNodeProperty().addListener((observable, oldValue, newValue) -> setBottom(newValue));
    }

    public void setBottom(Node node) {
        vBox.getChildren().set(1, node);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void layoutChildren(final double x, final double y,
                                  final double w, final double h) {
        super.layoutChildren(x, y, w, h);
    }

}